package com.study.module.datasource.config;

import com.study.module.datasource.enums.DataSourceType;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

import java.util.Optional;

public class DataSourceRouter extends AbstractRoutingDataSource {

    @Override
    protected Object determineCurrentLookupKey() {
        return Optional.ofNullable(DynamicContextHolder.get()).orElse(DataSourceType.MASTER).getCode();
    }

}
